import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { listModule } from '../module/module.api';
import { rules} from '/@/utils/helper/validator';
import {listUser} from "../user/user.api"

export const columns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 20,
    ifShow: false
  },
  {
    title: '所属服务',
    dataIndex: 'serviceName',
    width: 120,
  },

  {
    title: '资源名称',
    dataIndex: 'name',
    width: 120
  },

  {
    title: '资源路径',
    dataIndex: 'url',
    width: 160,
  },

  {
    title: '资源动作',
    dataIndex: 'action',
    width: 200,
  },

  {
    title: '动作类型',
    dataIndex: 'actionType',
    width: 90,
    customRender: ({ text }) => {
      const color = 'green';
      return render.renderTag(render.renderDict(text, 'ram_resource_action_type'), color)
    }
  },

  {
    title: '创建时间',
    dataIndex: 'createdAt',
    sorter: true,
    width: 150,
  },
  // {
  //   title: '状态',
  //   dataIndex: 'status',
  //   width: 50,
  //   customRender: ({ text }) => {
  //     const color = text === '1' ? 'green' : 'red';
  //     return render.renderTag(render.renderDict(text, 'tenant_status'), color)
  //   }
  // },

];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'serviceCode',
    label: '所属服务',
    component: 'JDictSelectTag',
    componentProps: {
      placeholder: '请选择',
      allowClear: true,
      showSearch: true,
      dictCode: 'service_code',
    },
    colProps: { span: 8 },
  },
  {
    field: 'action',
    label: '资源动作',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'actionType',
    label: '动作类型',
    component: 'JDictSelectTag',
    componentProps: {
      showSearch: true,
      dictCode:'ram_resource_action_type',
      placeholder:'请选择动作类型',
    },
    colProps: { span: 8 },
  },
  {
    field: 'fieldTime',
    component: 'RangePicker',
    label: '时间字段',
    componentProps: {
      valueType: 'Date',
    },
    colProps: {
      span: 8,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
    required: false
  },
  {
    label: '资源名称',
    field: 'name',
    component: 'Input',
    required: true
  },
  {
    label: '资源路径',
    field: 'url',
    component: 'Input',
    required: true
  },
  {
    label: '动作',
    field: 'action',
    component: 'Input',
    required: true
  },
  {
    field: 'actionType',
    label: '动作类型',
    component: 'JDictSelectTag',
    componentProps: {
      showSearch: true,
      dictCode:'ram_resource_action_type',
      placeholder:'请选择动作类型',
    },
    required: true
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
      rows: 5,
    },
  }
];



export const formDetailSchema : DescItem[] = [

  {
    field: 'serviceName',
    label: '所属服务',
  },
  {
    field: 'name',
    label: '资源名称'
  },
  
  {
    field: 'url',
    label: '资源路径'
  },

  {
    field: 'action',
    label: '资源动作'
  },

  {
    field: 'actionType',
    label: '动作类型',
    render: (curVal, data) => {
      const color = 'green';
      return render.renderTag(render.renderDict(curVal, 'ram_resource_action_type'), color)
    },
  },

  {
    field: 'createdAt',
    label: '创建时间'
  },

  {
    field: 'updatedAt',
    label: '更新时间'
  },

  {
    label: '备注',
    labelMinWidth: 60,
    field: 'remark',
  }
];


export const authorizeFromSchema: FormSchema[] = [
  {
    label: '权限空间',
    field: 'namespaceId',
    component: 'ApiSelect'
  }
];
